package test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ClearVSNew {
    static int n = 1000;
    static int total = 1_000_000;

    public static void main(String[] args) {
//        System.out.println(testClear(n));
        System.out.println(testNew(n));
    }

    public static long testNew(int n) {
        List<Integer> list;
        long sum = 0;
        while (n-- > 0) {
            list=new ArrayList<>(origin);
            start = System.currentTimeMillis();
            list = new ArrayList<>();
            end = System.currentTimeMillis();
            sum += end - start;
        }
        return end - start;
    }


    static long start;
    static long end;
    static List<Integer> origin = new ArrayList<>();

    static {
        for (int i = 0; i < total; i++) {
            origin.add(i);
        }
    }

    public static long testClear(int n) {
        List<Integer> list;
        long sum = 0;
        while (n-- > 0) {
            list=new ArrayList<>(origin);
            start = System.currentTimeMillis();
            list.clear();
            end = System.currentTimeMillis();
            sum += end - start;
        }
        return sum;
    }
}
